package com.tasks.server;

import org.apache.log4j.Logger;

import com.tasks.enums.Enum;

public class Column {
	
	// data types 
	public static final int INTEGER 	= 0;
	public static final int TEXT 		= 1;
	public static final int DATETIME 	= 2;
	public static final int BOOLEAN 	= 3;
	public static final int ENUM 		= 4;
	public static final int TABLE		= 5; 
	
	private String 	columnName; 
	private int 	dataType;
	private Object 	theData;	
	
	static Logger logger = Logger.getLogger(Column.class);
	
	public Column(String cName, int type) 
	{
		columnName = cName;
		dataType = type;
		theData = null;
	}
	
	public String getColumnName()
	{
		return columnName.toUpperCase();
	}

	public Object getData()
	{
		return theData;
	}
	
	public int getDataType() 
	{
		return dataType;
	}
	
	public void setData(Object o)
	{
		theData = o;
	}
	
	public String toString()
	{
		return theData != null ? theData.toString() : "";
	}
	
	public String toServer()
	{
		if(theData != null)
		{
			if(dataType == ENUM)
			{
				return "'" + ((Enum)theData).intValue() + "'";
			}
			else if (dataType == TABLE)
			{
				return  ((Table)theData).getPrimaryKey().toServer();
			}
			else 
			{
				return "'" + theData.toString() + "'";	
			}	
		}
		return "NULL";		
	}
}
